package org.malred.hotelsystem.fragment.admin;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;

import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import org.malred.hotelsystem.R;
import org.malred.hotelsystem.adapter.HotelRecycleAdapter;
import org.malred.hotelsystem.dao.HotelDao;
import org.malred.hotelsystem.fragment.BaseFragment;
import org.malred.hotelsystem.model.entity.HotelEntity;
import org.malred.hotelsystem.utils.DBUtil;

import java.util.ArrayList;
import java.util.List;

public class ManageHomeFragment extends BaseFragment {
    RecyclerView rv;
    private List<HotelEntity> hotelEntities;
    private HotelRecycleAdapter adapter;


//    @Override
//    public View onCreateView(LayoutInflater inflater, ViewGroup container,
//                             Bundle savedInstanceState) {
//        View root = inflater.inflate(R.layout.fragment_manage_home, container,false);
//        rv = root.findViewById(R.id.manage_rv);
//
//        SQLiteDatabase db = new DBUtil(inflater.getContext()).getReadableDatabase();
//        hotelEntities = new ArrayList<>();
//        hotelEntities = HotelDao.getAll(db);
//
//        adapter = new HotelRecycleAdapter(inflater.getContext(), hotelEntities);
//        rv.setAdapter(adapter);
//        // recycle view 显示方式(布局)
//        LinearLayoutManager manager = new LinearLayoutManager(inflater.getContext());
//        rv.setLayoutManager(manager);
//
//        return root;
//    }

    @Override
    protected int setLayoutResourceID() {
        return R.layout.fragment_manage_home;
    }

    @Override
    protected void setUpView() {
        rv = getContentView().findViewById(R.id.manage_rv);
    }

    @Override
    protected void setUpData() {
//        SQLiteDatabase db = new DBUtil(getMContext()).getReadableDatabase();
        hotelEntities = HotelDao.getAll(getDb());

        adapter = new HotelRecycleAdapter(getMContext(), hotelEntities);
        rv.setAdapter(adapter);
        // recycle view 显示方式(布局)
        LinearLayoutManager manager = new LinearLayoutManager(getMContext());
        rv.setLayoutManager(manager);
    }
}